package com.wetao.testrxjava;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

public class RecyclerViewAdapter extends RecyclerView.Adapter{
    private List<String> mData;
    private Context mContext;

    public RecyclerViewAdapter(Context context, List<String> data) {
        this.mContext = context;
        mData = data;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if(viewType == 1) {
            View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_list, parent, false);
            return new VoiceStudentInfoHolder(view);
        }
        return null;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        if (holder instanceof VoiceStudentInfoHolder) {
            ((VoiceStudentInfoHolder)holder).bindData(position);
        }
    }

    @Override
    public int getItemCount() {
        if(mData == null) {
            return 0;
        }
        return mData.size();
    }

    @Override
    public int getItemViewType(int position) {
        return 1;
    }


    class VoiceStudentInfoHolder extends RecyclerView.ViewHolder{

        TextView tv_item;


        public VoiceStudentInfoHolder( View itemView) {
            super(itemView);
            tv_item = itemView.findViewById(R.id.tv_item);
        }

        public void bindData(int position) {
            tv_item.setText(mData.get(position));
        }

    }
}
